<?php
/**
 * Created by PhpStorm.
 * User: xionghao
 * Date: 2017/10/17
 * Time: 1:48
 */

namespace app\volunteer\controller;


use app\volunteer\model\VolunteerLogModel;
use app\volunteer\model\VolunteerModel;
use cmf\controller\AdminBaseController;

class AdminVolunteerController extends AdminBaseController
{

    public function index()
    {
        $volunteerModel = new VolunteerModel();
        $name = $this->request->param('name');
        $phone = $this->request->param('phone');

        $where = [];
        if ($name) {
            $where['name'] = ['like', '%name%'];
        }
        if ($phone) {
            $where['phone'] = ['like', '%phone%'];
        }
        $volunteers = $volunteerModel->where($where)->paginate();
        $this->assign('list', $volunteers);
        $this->assign('page', $volunteers->render());
        return $this->fetch();
    }

    public function check()
    {
        $id = $this->request->param('id');
        $volunteerModel = new VolunteerModel();
        $volunteer = $volunteerModel->where('id', $id)->find();
        $this->assign('volunteer', $volunteer);
        return $this->fetch();
    }

    public function checkPost()
    {
        $id = $this->request->param('id');
        $status = $this->request->param('status', 0);
        $volunteer = VolunteerModel::get($id);
        $volunteer->status = $status;
        $volunteer->save();
        $this->success('保存成功');
    }

    public function logs()
    {
        $id = $this->request->param('id');
        $logModel = new VolunteerLogModel();
        $logs = $logModel->where('vid', $id)->paginate();
        $this->assign('logs', $logs);
        $this->assign('page', $logs->render());
        return $this->fetch();
    }
}